package com.hxz.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.hxz.interceptor.LoginInterceptor;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义拦截器
 * 
 * @author hxz
 * @description TODO
 * @data 2019年12月5日 上午9:35:36
 */
@Component
@Configuration
public class SessionInterceptorConfig implements WebMvcConfigurer {

	/**
	 * 自定义拦截器，添加拦截路径和排除拦截路径 addPathPatterns():添加需要拦截的路径
	 * excludePathPatterns():添加不需要拦截的路径
	 */
	// 注册拦截器
	public void addInterceptors(InterceptorRegistry registry) {
		List<String> list = new ArrayList<String>();
		list.add("/login");
		list.add("/swagger-ui.html");
		list.add("/druid/*");
		registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns(list);

	}
}
